package com.li.hello.domain;

import com.li.hello.entity.Persion;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

/**
 * redisTemplate
 */
@Repository
public class PersionDao {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;
//    @Resource(name = "stringRedisTemplate")
//    protected ValueOperations<String,String> strVos;

    @Autowired
    private RedisTemplate<Object, Object> redisTemplate;
//    @Resource(name = "redisTemplate")
//    protected ValueOperations<Object,Object> objVos;

    public void setPersion(Persion persion) {
        redisTemplate.opsForValue().set(persion.getId(), persion);//保存键值对
//        objVos.set(persion.getId(),persion);
        redisTemplate.expire(persion.getId(), 10, TimeUnit.SECONDS);//设置该键10秒后过期
        //redisTemplate.expire("persion::1",10,TimeUnit.SECONDS);
    }

    public Persion getPersion(Persion persion) {
//        return (Persion) objVos.get(persion.getId());
        return (Persion) redisTemplate.opsForValue().get(persion.getId());
    }
}
